package com.atguigu.app.WindowClose;

import com.atguigu.utils.KafkaUtil;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

//按照事件时间开窗，如果没有数据进入，那么最后一个窗口无法触发计算的解决方法
//用kafka生产者产生数据测试WindowTest
public class MyKafkaProducer {
    public static void main(String[] args) throws InterruptedException {
        Properties properties = new Properties();
        properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"hadoop102:9092");
        properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");

        KafkaProducer<String, String> stringStringKafkaProducer = new KafkaProducer<>(properties);

        int i= 0;
        while (true){
            i++;
            String value = "1001," + i + "," + System.currentTimeMillis();
            System.out.println(value);
            stringStringKafkaProducer.send(new ProducerRecord<>("test_01",value));

            Thread.sleep(1000);
        }
    }
}
